//
//  WHShowMoreCellController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/12/11.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "WHShowMoreCellController.h"
#import "WHShowMoreTableViewCell.h"
#import "WHShowMoreViewModel.h"
#import <Masonry.h>
#import "WHShowMoreHeader.h"

@interface WHShowMoreCellController ()
{
    BOOL Display[100];
}
@property (nonatomic, strong) WHShowMoreViewModel *viewModel;
@end

@implementation WHShowMoreCellController

- (WHShowMoreViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[WHShowMoreViewModel alloc] init];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.title = @"新手帮助";
    __weak typeof(self) weakSelf = self;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.left.mas_equalTo(weakSelf.view);
    }];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([WHShowMoreTableViewCell class]) bundle:nil] forCellReuseIdentifier:[WHShowMoreTableViewCell cellID]];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.viewModel.questionArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (Display[section] == YES) {
        return 1;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WHShowMoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[WHShowMoreTableViewCell cellID] forIndexPath:indexPath];
    cell.showTitle = self.viewModel.answerArr[indexPath.section];
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    WHShowMoreHeader *header = [WHShowMoreHeader header];
    header.contentTitle = self.viewModel.questionArr[section];
    header.showUp = Display[section];
    [header.moreSignal subscribeNext:^(id  _Nullable x) {
        Display[section] = !Display[section];
     //   NSIndexSet * set = [NSIndexSet indexSetWithIndex:section];
        [tableView reloadData];
        //[tableView reloadSections:set withRowAnimation:UITableViewRowAnimationNone];
    }];
    return header;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
    return 44;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}


@end
